<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.swing.*" %>
<%@ page import="java.util.List" %>
<%@ page import="bean.Rooms" %>
<%@page import="java.io.PrintWriter" %>
<%@ page import="bean.Login" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head> <meta charset="UTF-8">
    <title>房间查询</title>
</head>
    <style>
        table, th, td {
            border: solid 1px #efefef;
        }
        table {
            width: 100%;
            margin: auto;
            border-collapse: collapse;
            text-align: center;
            border-radius: 6px;
        }
        td,th{
            padding: 10px;
        }
        a {
            text-decoration-line: none;
            color: green;
        }
        a:hover {
            color: brown;
            text-decoration-line: underline;
        }
        tr:first-child {
            background-color: #efefef;
            border-radius: 4px 4px 0 0;
            border-bottom: solid 1px #ddd;
        }
        table caption {
            font-size: 1.5rem;
            font-weight: bolder;
            margin-bottom: 20px;
        }
        p {
            text-align: center;
        }
        /*首页样式*/
        p a:first-child {
            width: 56px;
        }
        p a:last-child {
            width: 56px;
        }
        p a {
            display: inline-block;
            width: 28px;
            height: 24px;
            border: 1px solid green;
            margin-left:2px;
            line-height: 24px;
        }
        /*当前页样式*/
        .active {
            background-color: green;
            color: white;
        }
        .more {
            border: none;
        }
    </style>
</head>
<body>
<center><h2>酒店房间信息</h2></center>
<table class="table table-hover text-center">
    <tbody><tr>
        <th width="10">房间编号</th>
        <th width="10">房间名称</th>
        <th width="10%">房型</th>
        <th width="35%">房价</th>
        <th width="10%">房间面积</th>
        <th width="15%">预定情况</th>
        <th width="20%">操作</th>
    </tr>
<hr>
    <jsp:useBean id="ad_login" class="bean.Login" scope="session"/>
<%
ad_login= (Login) session.getAttribute("ad_login");
String hotelID=ad_login.getLoginID();
%>
<br>
        <%
        Connection con=null;
        Statement sql;
        ResultSet rs;
        String roomID;
//    Context context=new InitialContext();
//    Context contextNeeded =(Context) context.lookup("java:comp/env");
//    DataSource ds=(DataSource) contextNeeded.lookup("hotelConn");
        String driver="org.mariadb.jdbc.Driver";
        String url="jdbc:mariadb://localhost:3306/hotel-management-system";
        try {
            Class.forName(driver);
            con= DriverManager.getConnection(url,"root","123456");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
//        con=ds.getConnection();
            assert con != null;
            sql=con.createStatement();
            //读取酒店详情表
            String ex="select * from rooms where HotelID in (select HotelName from hotels  where HotelID='"+hotelID+"')";
            rs=sql.executeQuery(ex);
            while (rs.next()){
                out.print("<tr>");
                roomID=rs.getString("RoomID");
                out.print("<td>"+rs.getString("RoomID")+"</td>");
                out.print("<td>"+rs.getString("RoomName")+"</td>");
                out.print("<td>"+rs.getString("RoomType")+"</td>");
                out.print("<td>"+rs.getString("Price")+"￥</td>");
                out.print("<td>"+rs.getString("RoomSize")+"平方米</td>");
                String condition=rs.getString("RoomCondi");
                if (condition.equals("1")){
                    condition="未预定";
                }else if (condition.equals("0")){
                    condition="已预定";
                }
                out.print("<td>"+condition+"</td>");
                out.print("<td><div> <a href='admin-update.jsp?roomID=\""+roomID+"\"'> 修改</a> <a href='adminDelete?roomID=\""+roomID+"\"'> 删除</a> </div></td>");
                out.print("</tr>");
            }
        }catch (SQLException e){
            System.out.print(e);
        }
        finally {
            try {
                assert con != null;
                con.close();
            }catch (Exception e){
                System.out.print(e);

            }
        }

    %>

</table>
</body>
</html>

